package com.cqut.forum.service.imp;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.cqut.forum.dao.PictureGroupDao;
import com.cqut.forum.entity.PictureGroup;
import com.cqut.forum.service.PictureGroupService;
import com.cqut.forum.util.MapKey;

/**
 * 图片组service实现类
 * @author yangxun
 */
@Controller
public class PictureGroupServiceImp implements PictureGroupService {
	
	@Resource
	private PictureGroupDao pictureGroupDao;
	
	@Override
	public PictureGroup delete(int pgId) {
		PictureGroup pg = pictureGroupDao.delete(pgId, PictureGroup.class);
		return pg;
	}

	@Override
	public PictureGroup getGroupById(int groupId) {
		PictureGroup pg = pictureGroupDao.get(groupId, PictureGroup.class);
		return pg;
	}

	@Override
	public List<PictureGroup> getGroups(int userId) {
		List<PictureGroup> groups = pictureGroupDao.getGroups(userId);
		return groups;
	}

	@Override
	public PictureGroup insert(PictureGroup pg) {
		pg = pictureGroupDao.save(pg);
		return pg;
	}

	@Override
	public PictureGroup update(PictureGroup pg) {
		pg = pictureGroupDao.update(pg);
		return pg;
	}

	@Override
	public Boolean exist(int userId,String pgName) {
		PictureGroup pg = pictureGroupDao.getByName(userId,pgName);
		return pg == null;
	}

	@Override
	public PictureGroup getGroupByName(int userId,String groupName) {
		PictureGroup pg = pictureGroupDao.getByName(userId,groupName);
		return pg;
	}

	@Override
	public int getGroupId(int pictureId) {
		int index = pictureGroupDao.getGroupId(pictureId);
		
		return index;
	}

	@Override
	public List<Map<String, Object>> getGroupsLikeName(String groupName) {
		List<Map<String, Object>> groups = pictureGroupDao.getGroupsLikeName(groupName);
		return groups;
	}

	@Override
	public List<Map<String, Object>> getSysteGroups() {
		List<Map<String, Object>> groups = pictureGroupDao.getSysteGroups();
		groups = MapKey.changeMapKey(groups);
		return groups;
	}

	@Override
	public boolean updateGroupName(int groupId, String groupName,boolean state) {
		pictureGroupDao.update(groupId,groupName,state);
		return true;
	}

	@Override
	public List<Map<String, Object>> getShowGroups() {
		List<Map<String, Object>> groups = pictureGroupDao.getShowGroups();
		groups = MapKey.changeMapKey(groups);
		return groups;
	}

}
